home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / p_image1.sit / LSP Source / Init.p < prev    next >
Encoding:
Text File  |  1989-07-29  |  22.7 KB  |  860 lines

  1. unit Initialization;
  2.  
  3. interface
  4.  
  5.  
  6.     uses
  7.         QuickDraw, OSIntf, PickerIntf, PrintTraps, ToolIntf, globals, Utilities, Graphics;
  8.  
  9.     procedure Init;
  10.     procedure AllocateBuffers;
  11.     procedure SetupMenus;
  12.     procedure GetSettings;
  13.  
  14.  
  15. implementation
  16.  
  17.  
  18.     procedure MakeCursors;
  19.   {Generates tool cursors from tool font. Thanks to Borland for "OffScreenDrawing"}
  20.   {and "MysteryCursor" examples in "Turbo Pascal Tutor".}
  21.         var
  22.             TempPort: GrafPort;
  23.             tPort: GrafPtr;
  24.             aRect, bRect: Rect;
  25.             OffScreenBitMap: BitMap;
  26.             BlankMask: Bits16;
  27.             tool: ToolType;
  28.             i: integer;
  29.             TempCurH: CursHandle;
  30.     begin
  31.         GetPort(tPort);
  32.         OpenPort(@TempPort);
  33.         with OffScreenBitMap do begin
  34.                 baseAddr := NewPtr(2 * 16); { allocate a bit image for 16x16 cursor}
  35.                 rowBytes := 2;              { 2 bytes per row}
  36.                 SetRect(bounds, 0, 0, 16, 16);  { define usable area and coordinate systme }
  37.             end;
  38.         SetPortBits(OffscreenBitMap);
  39.         for i := 0 to 15 do
  40.             BlankMask[i] := 0;
  41.         TextFont(ToolFont);
  42.         TextSize(12);
  43.         for tool := FirstTool to LastTool do begin
  44.                 EraseRect(OffscreenBitMap.bounds);
  45.                 MoveTo(0, 0);
  46.                 DrawChar(ToolCursorChar[tool]);
  47.                 with ToolCursor[tool] do begin
  48.                         BlockMove(OffscreenBitMap.BaseAddr, @data, 32);
  49.                         hotspot.h := 8;
  50.                         hotspot.v := 8;
  51.                         mask := BlankMask;
  52.                     end;
  53.             end;
  54.         SetPort(tPort);
  55.         TempCurH := GetCursor(PickerCursorID);
  56.         PickerCursor := TempCurH^^;
  57.         ReleaseResource(handle(TempCurH));
  58.         TempCurH := GetCursor(CrossCursorPlusID);
  59.         CrossPlusCursor := TempCurH^^;
  60.         ReleaseResource(handle(TempCurH));
  61.         TempCurH := GetCursor(CrossCursorMinusID);
  62.         CrossMinusCursor := TempCurH^^;
  63.         ReleaseResource(handle(TempCurH));
  64.         TempCurH := GetCursor(CrossCursorID);
  65.         ToolCursor[SelectionTool] := TempCurH^^;
  66.         ToolCursor[FreehandTool] := TempCurH^^;
  67.         ToolCursor[PolygonTool] := TempCurH^^;
  68.         ToolCursor[ruler] := TempCurH^^;
  69.         ToolCursor[PlotTool] := TempCurH^^;
  70.         ToolCursor[OvalSelectionTool] := TempCurH^^;
  71.         ToolCursor[RoundedRectTool] := TempCurH^^;
  72.         ToolCursor[AngleTool] := TempCurH^^;
  73.         ToolCursor[PointingTool] := TempCurH^^;
  74.         ReleaseResource(handle(TempCurH));
  75.         ToolCursor[PickerTool] := PickerCursor;
  76.         TempCurH := GetCursor(LUTCursorID);
  77.         LUTCursor := TempCurH^^;
  78.         ReleaseResource(handle(TempCurH));
  79.         TempCurH := GetCursor(gmCursorID);
  80.         gmCursor := TempCurH^^;
  81.         ReleaseResource(handle(TempCurH));
  82.         TempCurH := GetCursor(GrabberCursorID);
  83.         ToolCursor[Grabber] := TempCurH^^;
  84.         ReleaseResource(handle(TempCurH));
  85.         TempCurH := GetCursor(PencilCursorID);
  86.         ToolCursor[Pencil] := TempCurH^^;
  87.         ReleaseResource(handle(TempCurH));
  88.         TempCurH := GetCursor(GlassCursorPlusID);
  89.         ToolCursor[MagnifyingGlass] := TempCurH^^;
  90.         ReleaseResource(handle(TempCurH));
  91.         TempCurH := GetCursor(GlassCursorMinusID);
  92.         GlassMinusCursor := TempCurH^^;
  93.         ReleaseResource(handle(TempCurH));
  94.         TempCurH := GetCursor(BucketCursorID);
  95.         ToolCursor[PaintBucket] := TempCurH^^;
  96.         ReleaseResource(handle(TempCurH));
  97.         TempCurH := GetCursor(WandCursorID);
  98.         ToolCursor[Wand] := TempCurH^^;
  99.         ReleaseResource(handle(TempCurH));
  100.     end;
  101.  
  102.  
  103.     procedure InitTools;
  104.         var
  105.             ToolTop, LinesTop, i: integer;
  106.             Tool: ToolType;
  107.     begin
  108.         FirstTool := MagnifyingGlass;
  109.         LastTool := PointingTool;
  110.         CurrentTool := SelectionTool;
  111.         isSelectionTool := true;
  112.         PreviousTool := CurrentTool;
  113.         ToolTop := 0;
  114.         for tool := FirstTool to LastTool do
  115.             with ToolRect[tool] do begin
  116.                     top := ToolTop;
  117.                     bottom := top + tmiddle;
  118.                     if odd(ord(tool) + 1) then
  119.                         left := 0
  120.                     else begin
  121.                             left := tmiddle;
  122.                             ToolTop := ToolTop + tmiddle;
  123.                         end;
  124.                     right := left + tmiddle;
  125.                 end;
  126.         ToolChar[Pencil] := chr(76);
  127.         ToolChar[SelectionTool] := chr(70);
  128.         ToolChar[MagnifyingGlass] := chr(66);
  129.         ToolChar[TextTool] := chr(72);
  130.         ToolChar[Grabber] := chr(71);
  131.         ToolChar[Brush] := chr(75);
  132.         ToolChar[ruler] := chr(112);
  133.         ToolChar[PaintBucket] := chr(104);
  134.         ToolChar[AirBrushTool] := chr(74);
  135.         ToolChar[PlotTool] := chr(94);
  136.         ToolChar[Wand] := chr(101);
  137.         ToolChar[Eraser] := chr(78);
  138.         ToolChar[FreehandTool] := chr(69);
  139.         ToolChar[PolygonTool] := chr(87);
  140.         ToolChar[OvalSelectionTool] := chr(83);
  141.         ToolChar[PickerTool] := chr(77);
  142.         ToolChar[RoundedRectTool] := chr(97);
  143.         ToolChar[LUTTool] := chr(86);
  144.         ToolChar[AngleTool] := chr(106);
  145.         ToolChar[PointingTool] := chr(113);
  146.         ToolCursorChar[SelectionTool] := chr(89);
  147.         ToolCursorChar[Pencil] := chr(76);
  148.         ToolCursorChar[MagnifyingGlass] := chr(66);
  149.         ToolCursorChar[TextTool] := chr(110);
  150.         ToolCursorChar[Grabber] := chr(71);
  151.         ToolCursorChar[brush] := chr(103);
  152.         ToolCursorChar[ruler] := chr(89);
  153.         ToolCursorChar[PaintBucket] := chr(89);
  154.         ToolCursorChar[RoundedRectTool] := chr(89);
  155.         ToolCursorChar[LUTTool] := chr(86);
  156.         ToolCursorChar[FreehandTool] := chr(89);
  157.         ToolCursorChar[AirbrushTool] := chr(100);
  158.         ToolCursorChar[PolygonTool] := chr(89);
  159.         ToolCursorChar[PlotTool] := chr(89);
  160.         ToolCursorChar[Wand] := chr(100);
  161.         ToolCursorChar[Eraser] := chr(68);
  162.         ToolCursorChar[OvalSelectionTool] := chr(89);
  163.         ToolCursorChar[PickerTool] := chr(77);
  164.         ToolCursorChar[AngleTool] := chr(89);
  165.         ToolCursorChar[PointingTool] := chr(89);
  166.         ToolTime := 0;
  167.         LutTime := 0;
  168.         StartOfLines := ToolRect[LastTool].bottom - 1;
  169.         LinesTop := StartOfLines + 10;
  170.         for i := 1 to nLineTypes do
  171.             with lines[i] do begin
  172.                     left := LinesLeft;
  173.                     top := LinesTop;
  174.                     right := LinesRight;
  175.                     case i of
  176.                         1, 2, 3, 4: 
  177.                             bottom := top + i;
  178.                         5: 
  179.                             bottom := top + 6;
  180.                         6: 
  181.                             bottom := top + 8
  182.                     end;
  183.                     LinesTop := bottom + 4;
  184.                 end;
  185.         LineWidth := 1;
  186.         LineIndex := 1;
  187.         with CheckRect do begin
  188.                 left := 0;
  189.                 top := StartOfLines;
  190.                 right := LinesLeft;
  191.                 bottom := theight;
  192.             end;
  193.     end;
  194.  
  195.  
  196.     procedure AllocateBuffers;
  197.         var
  198.             tPort: GrafPtr;
  199.             err: OSErr;
  200.             BufSizeStr: str255;
  201.             atemp: integer;
  202.     begin
  203.         NumToString(BufferSize div 1024, BufSizeStr);
  204.         BigBufSize := BufferSize * 2;
  205.         if FreeMem > (BigBufSize + 300000) then
  206.             BigBuf := NewPtr(BigBufSize)
  207.         else
  208.             BigBuf := nil;
  209.         if BigBuf = nil then
  210.             BigBufSize := 0;
  211.         if BigBuf <> nil then
  212.             UndoBuf := BigBuf
  213.         else begin
  214.                 if FreeMem > (BufferSize + 200000) then
  215.                     UndoBuf := NewPtr(BufferSize)
  216.                 else
  217.                     UndoBuf := nil;
  218.             end;
  219.         if UndoBuf <> nil then
  220.             UndoBufSize := BufferSize
  221.         else begin
  222.                 PutMessage('There is not enough memory available to allocate the ', BufSizeStr, 'K Undo buffer. Many operations may fail or be Undoable.');
  223.                 UndoBufSize := 0;
  224.             end;
  225.         if BigBuf <> nil then
  226.             ClipBuf := ptr(ord4(BigBuf) + BufferSize)
  227.         else begin
  228.                 if FreeMem > (BufferSize + 300000) then
  229.                     ClipBuf := NewPtr(BufferSize)
  230.                 else
  231.                     ClipBuf := nil;
  232.             end;
  233.         if ClipBuf <> nil then begin
  234.                 ClipBufSize := BufferSize;
  235.                 ClipBufInfoRec := NoInfo^;
  236.                 with ClipBufInfo^ do begin
  237.                         osroiRgn := NewRgn;
  238.                         PicBaseAddr := ClipBuf;
  239.                         GetPort(tPort);
  240.                         new(osPort);
  241.                         OpenCPort(osPort);
  242.                         SetPort(tPort);
  243.                         osPort^.portPixMap^^.BaseAddr := PicBaseAddr;
  244.                         BytesPerRow := 0;
  245.                     end;
  246.             end
  247.         else begin
  248.                 PutMessage('There is not enough memory available to allocate the ', BufSizeStr, 'K Clipboard Buffer. Many operations, including Copy and Paste, may fail.');
  249.                 ClipBufSize := 0;
  250.             end;
  251.     end;
  252.  
  253.  
  254.     procedure GetSettings;
  255.         var
  256.             Size, ticks: LongInt;
  257.             ok: boolean;
  258.             SettingsH: handle;
  259.     begin
  260.         SettingsH := GetResource('SETT', 1000);
  261.         if (ResError = NoErr) and (SettingsH <> nil) then begin
  262.                 Size := GetHandleSize(SettingsH);
  263.                 if size = SizeOF(settings) then begin
  264.                         BlockMove(SettingsH^, @settings, size);
  265.                         with settings, info^ do begin
  266.                                 ForegroundColor := sForegroundColor;
  267.                                 BackgroundColor := sBackgroundColor;
  268.                                 BrushHeight := sBrushHeight;
  269.                                 BrushWidth := sBrushWidth;
  270.                                 AirbrushDiameter := sAirbrushDiameter;
  271.                                 LUTMode := sLUTMode;
  272.                                 ColorStart := sColorStart;
  273.                                 ColorWidth := sColorWidth;
  274.                                 CurrentFontID := sCurrentFontID;
  275.                                 CurrentStyle := SCurrentStyle;
  276.                                 CurrentSize := sCurrentSize;
  277.                                 TextJust := sTextJust;
  278.                                 TextBack := sTextBack;
  279.                                 nExtraColors := sNExtraColors;
  280.                                 ExtraColors := sExtraColors;
  281.                                 InvertVideo := sInvertVideo;
  282.                                 Measurements := sMeasurements;
  283.                                 InvertPlots := sInvertPlots;
  284.                                 AutoScalePlots := sAutoScalePlots;
  285.                                 LinePlot := sLinePlot;
  286.                                 DrawPlotLabels := sDrawPlotLabels;
  287.                                 ProfilePlotMin := sProfilePlotMin;
  288.                                 ProfilePlotMax := sProfilePlotMax;
  289.                                 FixedSizePlot := sFixedSizePlot;
  290.                                 ProfilePlotWidth := sProfilePlotWidth;
  291.                                 ProfilePlotHeight := sProfilePlotHeight;
  292.                                 nFrames := snFrames;
  293.                                 NewPicWidth := sNewPicWidth;
  294.                                 NewPicHeight := sNewPicHeight;
  295.                                 BufferSize := sBufferSize;
  296.                                 MaxScionWidth := sMaxScionWidth;
  297.                                 ThresholdToForeground := sThresholdToForeground;
  298.                                 NonThresholdToBackground := sNonThresholdToBackground;
  299.                                 VideoChannel := sVideoChannel;
  300.                                 WhatToImport := sWhatToImport;
  301.                                 ImportCustomWidth := sImportCustomWidth;
  302.                                 ImportCustomHeight := sImportCustomHeight;
  303.                                 ImportCustomOffset := sImportCustomOffset;
  304.                                 WandAutoMeasure := sWandAutoMeasure;
  305.                                 WandAutoNumber := sWandAutoNumber;
  306.                             end;
  307.                     end;
  308.                 case info^.LUTMode of
  309.                     ColorPalette, custom, CustomGrayscale: 
  310.                         UpdateColors;
  311.                     AppleDefault: 
  312.                         ok := LoadCLUTResource(AppleDefaultCLUT);
  313.                     Spectrum: 
  314.                         Load256ColorCLUT;
  315.                 end;
  316.                 if nExtraColors > 0 then
  317.                     RedrawCLUTWindow;
  318.             end;
  319.         ReleaseResource(SettingsH);
  320.         UpdateTextMenu;
  321.     end;
  322.  
  323.  
  324.     procedure MakePatterns;
  325. {Creates the patterns used to create the "marching ants". Thanks to}
  326. { Seth Snyder on CompuServe for the example.}
  327.         var
  328.             i, j: Integer;
  329.     begin
  330.         j := 0;
  331.         for i := 0 to 7 do begin
  332.                 pat[i][(j + 0) mod 8] := $1F;
  333.                 pat[i][(j + 1) mod 8] := $3E;
  334.                 pat[i][(j + 2) mod 8] := $7C;
  335.                 pat[i][(j + 3) mod 8] := $F8;
  336.                 pat[i][(j + 4) mod 8] := $F1;
  337.                 pat[i][(j + 5) mod 8] := $E3;
  338.                 pat[i][(j + 6) mod 8] := $C7;
  339.                 pat[i][(j + 7) mod 8] := $8F;
  340.                 j := j + 1;
  341.             end;
  342.         PatIndex := 0;
  343.     end;
  344.  
  345.  
  346.     procedure InitExtraColors;
  347.         var
  348.             i, j, ctop, cbottom, entry: integer;
  349.             tRect: rect;
  350.     begin
  351.         with ExtraColors[1] do begin
  352.                 red := -1;
  353.                 green := 0;
  354.                 blue := 0;
  355.             end;
  356.         with ExtraColors[2] do begin
  357.                 red := 0;
  358.                 green := -1;
  359.                 blue := 0;
  360.             end;
  361.         with ExtraColors[3] do begin
  362.                 red := 0;
  363.                 green := 0;
  364.                 blue := -1;
  365.             end;
  366.         with ExtraColors[4] do begin
  367.                 red := -1;
  368.                 green := -1;
  369.                 blue := 0;
  370.             end;
  371.         with ExtraColors[5] do begin
  372.                 red := 0;
  373.                 green := -1;
  374.                 blue := -1;
  375.             end;
  376.         with ExtraColors[6] do begin
  377.                 red := -1;
  378.                 green := 0;
  379.                 blue := -1;
  380.             end;
  381.         ctop := 256;
  382.         cbottom := ctop + ExtraColorsHeight;
  383.         for i := 1 to MaxExtraPlus2 do begin
  384.                 SetRect(tRect, 0, ctop, cwidth, cbottom);
  385.                 ExtraColorsRect[i] := tRect;
  386.                 ctop := ctop + ExtraColorsHeight;
  387.                 cbottom := cbottom + ExtraColorsHeight;
  388.             end;
  389.         ExtraColorsEntry[1] := WhiteC;
  390.         ExtraColorsEntry[2] := BlackC;
  391.         entry := FirstExtraColorsEntry;
  392.         j := 3;
  393.         for i := 1 to MaxExtraColors do begin
  394.                 ExtraColorsEntry[j] := entry;
  395.                 j := j + 1;
  396.                 Entry := Entry + 1;
  397.             end;
  398.     end;
  399.  
  400.  
  401.     function GetSlotBase (id: integer): LongInt;
  402.   {Returns the 24-bit slot base address of the NuBus card with the specified id.}
  403. {   Returns 0 if a card with the given id is not found.}
  404.         type
  405.             SPRAMRecord = packed record
  406.                     BoardId: integer;
  407.                     VenderUse: packed array[1..6] of SignedByte;
  408.                 end;
  409.         var
  410.             SlotBlock: SpBlock;
  411.             sparm: SPRAMRecord;
  412.             SparmAddr: LongInt;
  413.             i: integer;
  414.             err: OSErr;
  415.     begin
  416.         with SlotBlock do begin
  417.                 SparmAddr := LongInt(@sparm);
  418.                 spResult := SparmAddr;
  419.                 for i := 9 to 15 do begin
  420.                         spSlot := i;
  421.                         err := sReadPRAMRec(@SlotBlock);
  422.                         if sparm.BoardID = id then begin
  423.                                 GetSlotBase := spSlot * $100000;
  424.                                 exit(GetSlotBase)
  425.                             end;
  426.                     end;
  427.                 GetSlotBase := 0;
  428.             end;
  429.     end;
  430.  
  431.  
  432.     procedure LookForFrameGrabbers;
  433.         const
  434.             ControlRegOffset = $80000;
  435.             ChannelRegOffset = $80004;
  436.             DT2255id = $11A;
  437.             ScionID = $14B;
  438.         var
  439.             err: OSErr;
  440.             tPort: GrafPtr;
  441.             SlotBase: LongInt;
  442.     begin
  443.         SlotBase := GetSlotBase(ScionID);
  444.         if (SlotBase <> 0) and not OptionKeyDown then begin
  445.                 FrameGrabber := Scion;
  446.                 ScionSlotBase := SlotBase
  447.             end
  448.         else begin
  449.                 SlotBase := GetSlotBase(DT2255id);
  450.                 if SlotBase <> 0 then begin
  451.                         FrameGrabber := QuickCapture;
  452.                         DTSlotBase := SlotBase
  453.                     end
  454.                 else
  455.                     FrameGrabber := NoFrameGrabber
  456.             end;
  457.         if FrameGrabber = QuickCapture then begin
  458.                 ControlReg := ptr(DTSlotBase + ControlRegOffset);
  459.                 ChannelReg := ptr(DTSlotBase + ControlRegOffset + 4);
  460.                 ResetQuickCapture;
  461.             end;
  462.     end;
  463.  
  464.  
  465.     procedure MakeTiffDirectory;
  466.         var
  467.             i: integer;
  468.     begin
  469.         with TiffInfo do begin
  470.                 with header do begin
  471.                         ByteOrder := 'MM';
  472.                         Version := 42;
  473.                         FirstIFDOffset := 8;
  474.                     end;
  475.                 nEntries := 7;
  476.                 for i := 1 to nEntries do
  477.                     with directory[i] do begin
  478.                             ftype := 3;
  479.                             length := 1
  480.                         end;
  481.                 with directory[1] do begin
  482.                         TagField := SubFileType;
  483.                         offset := bsl(1, 16);
  484.                     end;
  485.                 with directory[2] do begin
  486.                         TagField := ImageWidth;
  487.                         offset := 0;
  488.                     end;
  489.                 with directory[3] do begin
  490.                         TagField := ImageLength;
  491.                         offset := 0;
  492.                     end;
  493.                 with directory[4] do begin
  494.                         TagField := BitsPerSample;
  495.                         offset := bsl(8, 16);
  496.                     end;
  497.                 with directory[5] do begin
  498.                         TagField := PhotoInterp;
  499.                         offset := 0;
  500.                     end;
  501.                 with directory[6] do begin
  502.                         TagField := StripOffsets;
  503.                         ftype := 4;
  504.                         offset := TiffDirSize + HeaderSize;
  505.                     end;
  506.                 with directory[7] do begin
  507.                         TagField := ImageHdrTag;
  508.                         ftype := 4;
  509.                         offset := TiffDirSize;
  510.                     end;
  511.                 NextIFD := 0;
  512.                 for i := 1 to TiffFillerSize do
  513.                     filler[i] := 0;
  514.             end;
  515.     end;
  516.  
  517.  
  518.     procedure CheckBits;
  519.         var
  520.             ColorQDExists: boolean;
  521.             MainDevice: GDHandle;
  522.             ScreenPixMap: PixMapHandle;
  523.             myEnvRec: SysEnvRec;
  524.             err: OSErr;
  525.     begin
  526.         err := SysEnvirons(1, myEnvRec);
  527.         ColorQDExists := (err <> envNotPresent) and MyEnvRec.HasColorQD;
  528.         if not ColorQDExists then begin
  529.                 PutMessage('Sorry, Image requires a Macintosh with Color QuickDraw.', '', '');
  530.                 ExitToShell;
  531.             end;
  532.         MainDevice := GetMainDevice;
  533.         if MainDevice^^.gdPmap^^.PixelSize <> 8 then begin
  534.                 PutMessage('Image requires 8-bit video. Use the Control Panel to switch to ', '256 color mode.', '');
  535.                 ExitToShell;
  536.             end;
  537.         ScreenPixMap := MainDevice^^.gdPMap;
  538.         ScreenRowBytes := BitAnd(ScreenPixMap^^.rowBytes, $1fff);
  539.         ScreenBase := ScreenPixMap^^.baseAddr;
  540.         RunningOn030 := MyEnvRec.processor = 4;
  541.     end;
  542.  
  543.  
  544.     procedure SetupMenus;
  545.         var
  546.             i: integer;
  547.     begin
  548.         AppleMenuH := GetMenu(AppleMenu);
  549.         InsertMenu(AppleMenuH, 0);
  550.         FileMenuH := GetMenu(FileMenu);
  551.         InsertMenu(FileMenuH, 0);
  552.         EditMenuH := GetMenu(EditMenu);
  553.         InsertMenu(EditMenuH, 0);
  554.         OptionsMenuH := GetMenu(OptionsMenu);
  555.         InsertMenu(OptionsMenuH, 0);
  556.         FunctionsMenuH := GetMenu(FunctionsMenu);
  557.         InsertMenu(FunctionsMenuH, 0);
  558.         AnalysisMenuH := GetMenu(AnalysisMenu);
  559.         InsertMenu(AnalysisMenuH, 0);
  560.         TextMenuH := GetMenu(TextMenu);
  561.         InsertMenu(TextMenuH, 0);
  562.         WindowsMenuH := GetMenu(WindowsMenu);
  563.         InsertMenu(WindowsMenuH, 0);
  564.  
  565.         BinaryMenuH := GetMenu(BinaryMenu);
  566.         InsertMenu(BinaryMenuH, -1);
  567.         FontMenuH := GetMenu(FontMenu);
  568.         InsertMenu(FontMenuH, -1);
  569.         SizeMenuH := GetMenu(SizeMenu);
  570.         InsertMenu(SizeMenuH, -1);
  571.         StyleMenuH := GetMenu(StyleMenu);
  572.         InsertMenu(StyleMenuH, -1);
  573.  
  574.         DrawMenuBar;
  575.         AddResMenu(AppleMenuH, 'DRVR');
  576.         AddResMenu(FontMenuH, 'FONT');
  577.         NumFontItems := CountMItems(FontMenuH);
  578.     end;
  579.  
  580.  
  581.     procedure Init;
  582.         var
  583.             i: integer;
  584.             p: SyspPtr;
  585.             mbhp: ^integer;
  586.     begin
  587.         SetApplLimit(ptr(LongInt(GetApplLimit) - StackSize));
  588.         MaxApplZone;
  589.         InitGraf(@ThePort);
  590.         InitFonts;
  591.         InitWindows;
  592.         InitCursor;
  593.   {PLHeapInit(100000,5000,Nil,true,true)-Needed for MPW}
  594.         TEInit;
  595.         InitDialogs(@SysResume);
  596.         CheckBits;
  597.         new(ScreenPort);
  598.         OpenPort(ScreenPort);
  599.         NoInfo := @NoInfoRec;
  600.         Info := NoInfo;
  601.         ResultsWindow := nil;
  602.         with NoInfo^ do begin
  603.                 nlines := 0;
  604.                 PixelsPerLine := 0;
  605.                 PicSize := 0;
  606.                 PicBaseAddr := nil;
  607.                 osPort := nil;
  608.                 RoiShowing := false;
  609.                 RoiType := NoRoi;
  610.                 roiRect := SrcRect;
  611.                 osRoiRect := SrcRect;
  612.                 osroiRgn := NewRgn;
  613.                 title := 'NoInfo';
  614.                 Magnification := 1.0;
  615.                 PictureType := NullPicture;
  616.                 wptr := nil;
  617.                 Changes := false;
  618.                 BytesPerRow := 0;
  619.                 PixMapSize := 0;
  620.                 SetRect(SrcRect, 0, 0, 0, 0);
  621.                 PicRect := SrcRect;
  622.                 wrect := SrcRect;
  623.                 savewrect := SrcRect;
  624.                 ScaleToFitWindow := false;
  625.                 ColorStart := 30;
  626.                 ColorWidth := 8;
  627.                 LUTMode := GrayScale;
  628.                 units := 'mm';
  629.                 UnitsID := 7;
  630.                 scale := 0.0;
  631.                 UnitOfMeasure := '';
  632.                 PicNum := 1;
  633.                 HeaderOffset := -1;
  634.                 ImageDataOffset := -1;
  635.                 for i := 0 to 255 do
  636.                     ctable[i].value := 0;
  637.                 Fit := Poly3;
  638.                 Calibrated := false;
  639.                 nCoefficients := 0;
  640.                 for i := 1 to 6 do
  641.                     Coefficient[i] := 0.0;
  642.                 p1x := 0;
  643.                 p1y := 0;
  644.                 p2x := 255;
  645.                 p2y := 255;
  646.                 deltax := 255;
  647.                 deltay := 255;
  648.                 BinaryPic := false;
  649.             end;
  650.         new(CScreenPort);
  651.         OpenCPort(CScreenPort);
  652.         finished := false;
  653.         FlushEvents(EveryEvent, 0);
  654.         for i := 1 to 10 do
  655.             MoreMasters;
  656.         mbhp := pointer(MBarHeight);
  657.         MenuBarHeight := mbhp^;
  658.         SetRect(trect, tleft, ttop, tleft + twidth, ttop + theight);
  659.         ToolWindow := NewCWindow(nil, trect, 'Tools', true, NoGrowDocProc, nil, false, 0);
  660.         WindowPeek(ToolWindow)^.WindowKind := ToolKind;
  661.         BringToFront(ToolWindow);
  662.         ScreenWidth := ScreenBits.Bounds.right;
  663.         ScreenHeight := ScreenBits.Bounds.bottom;
  664.         with BlackRGB do begin
  665.                 red := 0;
  666.                 blue := 0;
  667.                 green := 0;
  668.             end;
  669.         with WhiteRGB do begin
  670.                 red := -1;
  671.                 blue := -1;
  672.                 green := -1;
  673.             end;
  674.         RGBForeColor(WhiteRGB); {CopyBits seems to require this}
  675.         RGBBackColor(WhiteRGB);
  676.         ThresholdStart := 100;
  677.         ThresholdEnd := 150;
  678.         with ThresholdColor do begin
  679.                 red := -1;
  680.                 green := 0;
  681.                 blue := 0;
  682.             end;
  683.         Thresholding := false;
  684.         nExtraColors := 0;
  685.         GrayMapReady := false;
  686.         ResetGrayMap;   {LUT must be setup before InitMenus}
  687.         InitMenus;
  688.         SetRect(gmrect, gmleft, gmtop, gmleft + gmwidth, gmtop + gmheight);
  689.         SetRect(gmSlide1, gmrectleft, gmrectbottom + gmSlide1Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide1Offset + gmSlideHeight);
  690.         gmSlide1i := gmSlide1;
  691.         InsetRect(gmSlide1i, 1, 1);
  692.         SetRect(gmSlide2, gmrectleft, gmrectbottom + gmSlide2Offset, gmrectleft + gmSlideWidth, gmrectbottom + gmSlide2Offset + gmSlideHeight);
  693.         gmSlide2i := gmSlide2;
  694.         gmFixedSlope := false;
  695.         InsetRect(gmSlide2i, 1, 1);
  696.         SetRect(gmIcon1, gmIcon1left, gmrectbottom + gmIconOffset, gmIcon1left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight);
  697.         SetRect(gmIcon2, gmIcon2left, gmrectbottom + gmIconOffset, gmIcon2left + gmIconWidth, gmrectbottom + gmIconOffset + gmIconHeight);
  698.         GrayMapWindow := NewWindow(nil, gmrect, ' Gray Map ', true, NoGrowDocProc, nil, false, 0);
  699.         WindowPeek(GrayMapWindow)^.WindowKind := GrayMapKind;
  700.         SetRect(GrayMapRect, gmRectLeft, gmRectTop, gmRectRight, gmRectBottom);
  701.         GrayMapRect2 := GrayMapRect;
  702.         InsetRect(GrayMapRect2, -2, -2);
  703.         cheight := 256 + (2 + nExtraColors) * ExtraColorsHeight;
  704.         SetRect(crect, cleft, ctop, cleft + cwidth, ctop + cheight);
  705.         LUTWindow := NewCWindow(nil, crect, 'LUT', true, NoGrowDocProc, nil, false, 0);
  706.         WindowPeek(LUTWindow)^.WindowKind := LUTKind;
  707.         if ScreenHeight > 480 then begin
  708.                 rleft := 5;
  709.                 rtop := ScreenHeight - rheight - 5;
  710.             end
  711.         else begin
  712.                 rleft := 2;
  713.                 rtop := 358;
  714.             end;
  715.         SetRect(trect, rleft, rtop, rleft + rwidth, rtop + rheight);
  716.         ResultsWindow := NewWindow(nil, trect, 'Results', true, NoGrowDocProc, nil, false, 0);
  717.         BringToFront(ResultsWindow);
  718.         WindowPeek(ResultsWindow)^.WindowKind := ResultsKind;
  719.         UpdateRegion := NewRgn;
  720.         watch := GetCursor(WatchCursor);
  721.         InitTools;
  722.         MakeCursors;
  723.         nPics := 0;
  724.         HistoWindow := nil;
  725.         PlotWindow := nil;
  726.         IsInsertionPoint := false;
  727.         MaskRgn := NewRgn;
  728.         PlotPICT := nil;
  729.         AutoscalePlots := true;
  730.         InvertPlots := false;
  731.         LinePlot := true;
  732.         DrawPlotLabels := true;
  733.         FixedSizePlot := false;
  734.         ProfilePlotMin := 0;
  735.         ProfilePlotMax := 255;
  736.         ProfilePlotWidth := 300;
  737.         ProfilePlotHeight := 150;
  738.         AirbrushDiameter := 16;
  739.         AirbrushRadius := 8;
  740.         AirbrushRadius2 := 64;
  741.         BrushWidth := 14;
  742.         BrushHeight := 14;
  743.         CurrentUndoSize := 0;
  744.         p := GetSyspPtr;
  745.         BlinkTime := BitAnd($000F, p^.volclik) * 4;
  746.         MakePatterns;
  747.         InitColor('Default', 0);
  748.         info^.LUTMode := GrayScale;
  749.         PaletteName := '';
  750.         PicWindowLeft := twidth + cwidth + 10;
  751.         PicWindowTop := MenuBarHeight + 20;
  752.         ClipBufInfo := @ClipBufInfoRec;
  753.         CurrentColorIndex := NoColor;
  754.         CurrentFontID := Helvetica;
  755.         CurrentStyle := []; {plain}
  756.         CurrentSize := 24;
  757.         TextJust := LeftJust;
  758.         TextBack := NoBack;
  759.         MouseState := NotInRoi;
  760.         WhatsOnClip := Nothing;
  761.         PasteMode := NormalPaste;
  762.         InitExtraColors;
  763.         OldScrapCount := GetScrapCount;
  764.         ScrapNotCleared := true;
  765.         ClipboardConverted := false;
  766.         with results do begin
  767.                 n := 0;
  768.                 min := -1;
  769.                 max := -1;
  770.                 x := 0;
  771.                 y := 0;
  772.                 Length := 0.0;
  773.                 angle := 0;
  774.             end;
  775.         LookForFrameGrabbers;
  776.         VideoChannel := 0;
  777.         Digitizing := false;
  778.         debugging := false;
  779.         BlankFieldInfo := nil;
  780.         CameraInfo := nil;
  781.         ScionInfo := nil;
  782.         DebugInfo := nil;
  783.         InvertVideo := false;
  784.         PlotCount := 0;
  785.         TextOnClip := false;
  786.         new(TextBufP);
  787.         if TextBufP = nil then
  788.             ExitToShell;
  789.         nAreas := 0;
  790.         nAreas2 := 0;
  791.         UnsavedAreas := 0;
  792.         nPoints := 0;
  793.         UnsavedPoints := 0;
  794.         nLengths := 0;
  795.         UnsavedLengths := 0;
  796.         lengths[0] := 0.0;
  797.         TotalLength := 0.0;
  798.         mean[0] := 0.0;
  799.         sd[0] := 0.0;
  800.         PixelCount[0] := 0;
  801.         mode[0] := 0.0;
  802.         IntegratedDensity[0] := 0.0;
  803.         plength[0] := 0.0;
  804.         for i := 1 to MaxStandards do
  805.             StandardValues[i] := BadReal;
  806.         nStandards := 0;
  807.         for i := 0 to 255 do
  808.             value[i] := i;
  809.         WhatToUndo := NothingToUndo;
  810.         WhatToCopy := NothingToCopy;
  811.         PrintRecord := nil;
  812.         printing := false;
  813.         ShowingList := false;
  814.         HalftoneFrequency := 50;
  815.         HalftoneAngle := 45;
  816.         HalftoneDotFunction := true;
  817.         Return := chr(13);
  818.         tab := chr(9);
  819.         BackSpace := chr(8);
  820.         measuring := false;
  821.         measurements := [AreaM, MeanM];
  822.         nMeasurements := 0;
  823.         ContinuousHistogram := false;
  824.         nFrames := 16;
  825.         PixelLength := 0.0;
  826.         ValuesMode := NoValues;
  827.         Copying := false;
  828.         NewPicWidth := 600;
  829.         NewPicHeight := 512;
  830.         RestoreUndoBuf := true;
  831.         MakeTiffDirectory;
  832.         BufferSize := DefaultBufferSize;
  833.         MaxScionWidth := 600;
  834.         ThresholdToForeground := true;
  835.         NonThresholdToBackground := true;
  836.         SelectionMode := NewSelection;
  837.         RoiMovementState := Unconstrained;
  838.         PasteControl := nil;
  839.         PasteTransferMode := SrcCopy;
  840.         WhatToImport := ImportTIFF;
  841.         ImportCustomWidth := 512;
  842.         ImportCustomHeight := 512;
  843.         ImportCustomOffset := 0;
  844.         RoiNudged := false;
  845.         SetForegroundColor(BlackC);
  846.         SetBackgroundColor(WhiteC);
  847.         for i := 0 to MaxPixelsPerLine - 1 do
  848.             BlankLine[i] := WhiteC;
  849.         SavingOutline := false;
  850.         RestoringOutline := false;
  851.         OpPending := false;
  852.         RedoSelection := false;
  853.         WandAutoMeasure := false;
  854.         WandAutoNumber := false;
  855.         for i := 0 to MaxAreas do
  856.             plength[i] := 0.0;
  857.     end;
  858.  
  859.  
  860. end.